package SortTemplate;

public class QuickSort_1 {
    /*
    快速排序的最简单模版式写法
    左闭右闭的二分写法
    调用时应该传入 l = 0, r = nums.length
     */
    public void quickSort(int[] nums, int l, int r) {
        // 退出条件
        if (l + 1 > r) return;
        int first = l, last = r - 1, key = nums[first];
        while (first < last) {
            while (first < last && nums[last] >= key) --last;
            nums[first] = nums[last];
            while (first < last && nums[first] <= key) ++first;
            nums[last] = nums[first];
        }
        nums[first] = key;
        quickSort(nums, l, first);
        quickSort(nums, first + 1, r);
    }

}
